package com.zlq.cn.admin.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zlq.cn.admin.domain.SysConfig;
import com.zlq.cn.admin.mapper.SysConfigMapper;
import com.zlq.cn.util.EncryptUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统配置表 服务实现类
 * </p>
 *
 * @author zhoucl
 * @since 2022-12-21
 */
@Service
public class SysConfigService extends ServiceImpl<SysConfigMapper, SysConfig> {

    public static final String CONFIG_CITY_TIME = "CONFIG_CITY_TIME";

    public static final String CONFIG_AES_LINK = "CONFIG_AES_LINK";

    public static final String AES_LINK_PASSWORD = "00000000";

    public Boolean edit(SysConfig sysConfig) {
        if (CONFIG_AES_LINK.equals(sysConfig.getUnKey()) && StringUtils.isNotEmpty(sysConfig.getValue())) {
            sysConfig.setValueExt(EncryptUtils.aes256ECBPkcs7PaddingEncrypt(sysConfig.getValue(), AES_LINK_PASSWORD));
        }
        if (!super.updateById(sysConfig)) {
            super.save(sysConfig);
        }
        return Boolean.TRUE;
    }
}
